package org.splink.deepsplink.deeplink {
	import org.splink.deepsplink.page.params.PageParameter;
	import org.splink.deepsplink.page.params.PageParameterUtil;

	/**
	 * @author Max Kugland
	 */
	final internal class Request {
		private var _id : String;
		private var _params : Array;

		public function get fullId() :String {
			return PageParameterUtil.constructId(id, params);
		}

		public function Request(id : String, params : Array) {
			_id = id;
			_params = params ? params : new Array();
		}

		/**
		 * Create a new <code>Request</code> instance from a full id
		 */
		public static function fromFullId(id : String, homeId : String) : Request {
			return new Request(PageParameterUtil.extractId((id == "") ? homeId : id), PageParameterUtil.extractParams(id));
		}

		/**
		 * @return whether the given <code>Request</code> instance is equal
		 * to this 
		 */
		public function equals(r : Request) : Boolean {
			if(r == null)
				return false;
			if(r.id != id)
				return false;
			if(r.params.length != params.length)
				return false;

			for (var i : int = 0;i < params.length;i++) {
				var p : PageParameter = params[i];
				if(!p.equals(r.params[i]))
					return false;
			}
			return true;
		}

		/**
		 * @return the id of the requested page 
		 */
		public function get id() : String {
			return _id;
		}

		/**
		 * @return an <code>Array</code> of <code>PageParameter</code> instances
		 * which define the parameters of the requested page 
		 */
		public function get params() : Array {
			return _params.concat();
		}
	}
}